package com.example.flowable.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.annotations.Autowired;
import com.example.annotations.PostMapping;
import com.example.annotations.RequestBody;
import com.example.annotations.RestController;
import com.example.flowable.model.FormModel;
import com.example.flowable.service.FormModelService;
import com.example.utils.Results;

import java.util.Date;

/**
 * @Classname FormModelController
 * @Description TODO
 * @Date 2022/8/16 11:19
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RestController("/form")
public class FormModelController {

    @Autowired
    FormModelService formModelService;

    @PostMapping(value = "/save",desc = "表单保存")
    public JSONObject saveFormModelController(@RequestBody JSONObject jsonObject){
        String html=jsonObject.getString("html");
        JSONObject fields=jsonObject.getJSONObject("fields");
        String fieldsJsonStr=fields.toJSONString();
        FormModel formModel=new FormModel();
        formModel.setFormfield(fieldsJsonStr);
        formModel.setCreatedate(new Date());
        formModel.setFormhtml(html);
        formModelService.save(formModel);
        return Results.success("保存成功");
    }


}
